home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_remoteP.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  46.8 KB  |  1,647 lines

  1. /*****************************************************************************
  2.   FILE           : ui_remoteP.c
  3.   SHORTNAME      : remoteP.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : routines to control learning, updating the net
  7.   NOTES          : Most of this routines are callbacks of buttons in the remote-
  8.                    panel.
  9.  
  10.   AUTHOR         : Tilman Sommer
  11.   DATE           : 18.7.1990
  12.  
  13.   CHANGED BY     : Michael Vogt, Guenter Mamier
  14.   IDENTIFICATION : @(#)ui_remoteP.c    1.33 4/18/94
  15.   SCCS VERSION   : 1.33 
  16.   LAST CHANGE    : 4/18/94  
  17.  
  18.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  19.              
  20. ******************************************************************************/
  21.  
  22.  
  23. #include <stdio.h>
  24.  
  25. #include "ui.h"
  26. #include "ui_mainP.h"
  27. #include "ui_utilP.h"
  28. #include "ui_selection.h"
  29. #include "ui_netUpdate.h"
  30.  
  31. #include "glob_typ.h"
  32. #include "kr_ui.h"
  33.  
  34. #include "ui_fileP.h"
  35. #include "ui_confirmer.h"
  36. #include "ui_textP.h"
  37. #include "ui_xWidgets.h"
  38. #include "ui_display.h"
  39. #include "ui_action.h"
  40. #include "ui_remote.h"
  41. #include "ui_status.h"
  42. #include "ui_infoP.h"
  43. #include "d3_main.h"
  44. #include "net_analyzer.h"
  45.  
  46. #include "kr_typ.h"
  47. #include "cc_rcc.h"
  48. #include "cc_main.h"
  49. #include "dlvq_learn.h"
  50. #include "ui_inversion.h"
  51. #include "ui_kohonen.h"
  52.  
  53.  
  54. #include "o_graph.h"
  55. #include "ui_main.h"
  56. #include "ui_event.h"
  57.  
  58. #include <X11/Xaw/Form.h>
  59. #include <X11/Shell.h>
  60. #include <X11/Xaw/SmeBSB.h>
  61. #include <X11/IntrinsicP.h>
  62. #include <X11/CoreP.h>
  63. #include <X11/Intrinsic.h>
  64.  
  65. #include "ui_remoteP.ph"
  66.  
  67.  
  68. /*****************************************************************************
  69.   FUNCTION : ui_rem_displayCounter
  70.  
  71.   PURPOSE  : displays the value in ui_numberOfStepsDone in the remote panel
  72.   RETURNS  : void
  73.   NOTES    :
  74.  
  75.   UPDATE   :
  76. *****************************************************************************/
  77. static void ui_rem_displayCounter (void)
  78. {
  79.     char  buf[50];
  80.     if (NOT ui_remoteIsCreated) return;
  81.  
  82.     sprintf(buf,"%d", ui_numberOfStepsDone);
  83.     ui_xSetLabel(ui_numberOfStepsDoneWidget, buf);
  84. }
  85.  
  86.  
  87. /*****************************************************************************
  88.   FUNCTION : ui_rem_displayPatternNumber
  89.  
  90.   PURPOSE  : displays the value in ui_numberOfCurrentPattern in the 
  91.              remote panel
  92.   RETURNS  : void
  93.   NOTES    :
  94.  
  95.   UPDATE   :
  96. *****************************************************************************/
  97. void ui_rem_displayPatternNumber (void)
  98. {
  99.     char  buf[50];
  100.  
  101.     if (NOT ui_remoteIsCreated) return;
  102.  
  103.     sprintf(buf,"%d", ui_noOfCurrentPattern);
  104.     ui_xSetString(ui_numberOfPatternWidget, buf);
  105.     ui_xSetLabel(ui_showPattFile, PATTERN_SET_FILE[CURR_PATTERN_SET]);
  106. }
  107.  
  108.  
  109.  
  110. /*****************************************************************************
  111.   FUNCTION : ui_rem_resetCounter()
  112.  
  113.   PURPOSE  : set counter to 0
  114.   RETURNS  : VOID
  115.   NOTES    :
  116.  
  117.   UPDATE   : 30.7.1990
  118. ******************************************************************************/
  119. void ui_rem_resetCounter (void)
  120. {
  121.     ui_numberOfStepsDone = 0;
  122.     ui_rem_displayCounter();
  123. }
  124.  
  125.  
  126.  
  127. /*****************************************************************************
  128.   FUNCTION : ui_rem_incCounter()
  129.  
  130.   PURPOSE  : increment counter by 1
  131.   RETURNS  :
  132.   NOTES    :
  133.  
  134.   UPDATE   : 30.7.1990
  135. ******************************************************************************/
  136. static void ui_rem_incCounter (void)
  137. {
  138.     ui_numberOfStepsDone += 1;
  139.     ui_rem_displayCounter();
  140. }
  141.  
  142.  
  143. /*****************************************************************************
  144.   FUNCTION : ui_rem_resetNet
  145.  
  146.   PURPOSE  : Resets the net to the initial activation and resets the counter
  147.   NOTES    :
  148.  
  149.   UPDATE   : 24.8.1990
  150. ******************************************************************************/
  151. void ui_rem_resetNet (Widget w, XtPointer button, caddr_t call_data)
  152. {
  153.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  154.     ui_net_updateWhole(NULL, UI_GLOBAL, UI_DRAW_UNITS, UI_ERASE);
  155.     krui_resetNet();
  156.     ui_rem_resetCounter();
  157.     ui_net_updateWhole(NULL, UI_GLOBAL, UI_DRAW_UNITS, UI_DRAW);
  158.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  159. }
  160.  
  161.  
  162. /*****************************************************************************
  163.   FUNCTION : ui_rem_doInitialization
  164.  
  165.   PURPOSE  : get the parameters and call the kernel
  166.   RETURNS  : void
  167.   NOTES    : 
  168.  
  169.   UPDATE   : 18.3.1991
  170. ******************************************************************************/
  171. void ui_rem_doInitialization (Widget w, caddr_t client_data, caddr_t call_data)
  172. {
  173.     int i;
  174.  
  175.     if(o_open){
  176.       o_CurveNo += ((o_CurveLengths[o_CurveNo] != 0) && 
  177.             (o_CurveNo < MAX_CURVE_NO-1)) ? (1) : (0);
  178.       o_InitCurve();
  179.       o_LearnStepCount = 0;
  180.     }
  181.  
  182.     for (i=0; i< UI_NO_INIT_PARAMS; i++) {
  183.     ui_initParameters[i] =
  184.         ui_xFloatFromAsciiWidget(ui_initParameterWidgets[i]);
  185.     }
  186.     ui_checkError(krui_initializeNet(ui_initParameters, UI_NO_INIT_PARAMS));
  187.     if (ui_displ_isSomeWhereToShowWeights())
  188.     ui_net_completeRefresh(NULL, UI_GLOBAL);
  189.     else {
  190.         ui_net_completeRefresh(NULL, UI_GLOBAL);
  191.     ui_net_updateWhole(NULL, UI_GLOBAL, UI_DRAW_UNITS, UI_DRAW);  
  192.     }
  193.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  194. }
  195.  
  196.  
  197. /*****************************************************************************
  198.   FUNCTION : ui_rem_deleteNet
  199.  
  200.   PURPOSE  : clear SNNS kernel
  201.   RETURNS  : void
  202.   NOTES    : 
  203.  
  204.   UPDATE   : 18.3.1991
  205. ******************************************************************************/
  206.  
  207. void ui_rem_deleteNet (Widget w, caddr_t client_data, caddr_t call_data)
  208.  
  209. {
  210.     if (ui_confirmYes
  211.     ("CLEAR: The network and all patterns will be lost. Clear?")) {
  212.     /* reset kernel */
  213.     krui_deleteNet();
  214.     /* reset gui */
  215.     ui_sel_resetList();       /* reset selections */
  216.     ui_net_completeRefresh(NULL, UI_GLOBAL); /* show net */
  217.     ui_printMessage("");
  218.     ui_stat_displayStatus(ui_gridPosMouse);
  219.     ui_file_updateShellLabels();
  220.     ui_info_makeUnitInfoPanelConsistent();    
  221.         d3_clear_xyTranslationTable ();
  222.     if (INVERS_CREATED) {
  223.            XtDestroyWidget(ui_InvRootWidget);
  224.            INVERS_CREATED = 0;
  225.        }
  226.     }
  227. }
  228.  
  229.  
  230. /*****************************************************************************
  231.   FUNCTION : ui_rem_finishSteps
  232.  
  233.   PURPOSE  : finish performing update steps
  234.   RETURNS  : void
  235.   NOTES    :
  236.  
  237.   UPDATE   : 1.2.1990
  238. ******************************************************************************/
  239.  
  240. static void ui_rem_finishSteps (void)
  241.  
  242. {
  243.     ui_printMessage("");
  244.  
  245.     /* reshow selection markers */
  246.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); 
  247. }
  248.  
  249.  
  250. /*****************************************************************************
  251.   FUNCTION : ui_rem_performStep
  252.  
  253.   PURPOSE  : called by pressing the button STEPS
  254.   RETURNS  : void
  255.   NOTES    :
  256.  
  257.   UPDATE   :
  258. *****************************************************************************/
  259.  
  260. static Boolean ui_rem_performStep (caddr_t client_data)
  261.  
  262. {
  263.     if (ui_numberOfWorkCycles-- < 1) {
  264.     ui_rem_finishSteps();
  265.     if (NA_ContinueTest()) 
  266.         ui_rem_testProc (NULL, NULL, NULL) ; 
  267.     return(TRUE);
  268.     }
  269.     /* erase the units first, if they have to be drawn with their values
  270.        in numerical form at the bottom (setup parameter) */
  271.     if (ui_displ_isSomeWhereToShowValues())
  272.     ui_net_updateWhole(NULL, UI_GLOBAL, 
  273.                UI_DRAW_UNITS, UI_ERASE_BOTTOM);
  274.     ui_checkError(krui_updateNet(ui_updateParameters, UI_NO_UPDATE_PARAMS));
  275.     ui_rem_incCounter();
  276.     ui_net_updateWhole(NULL, UI_GLOBAL, UI_DRAW_UNITS, UI_DRAW);
  277.     NA_DrawNextPoint () ;
  278.     return(FALSE);
  279. }
  280.  
  281.  
  282. /*****************************************************************************
  283.   FUNCTION : ui_rem_stepsProc
  284.  
  285.   PURPOSE  : perform one or more steps, depending on the PANEL_CLIENT_DATA
  286.              if STEP is pressed one update step in the current mode
  287.          if STEPS is pressed: get the number of steps to perform
  288.          from the panel and go.
  289.   RETURNS  : void
  290.   NOTES    :
  291.  
  292.   UPDATE   :
  293. *****************************************************************************/
  294.  
  295. void  ui_rem_stepsProc (Widget widget, Bool multiStepPressed, caddr_t call_data)
  296.  
  297.     char   buf[80];
  298.     int    i;
  299.  
  300.     if (multiStepPressed) 
  301.     /* MultiSTEPS button */
  302.     if ((ui_numberOfWorkCycles = 
  303.          ui_xIntFromAsciiWidget(ui_numberOfStepsWidget)) <= 0)
  304.         return;
  305.     
  306.     sprintf(buf,"%d steps. Calculating ...", ui_numberOfWorkCycles);
  307.     ui_printMessage(buf);
  308.    
  309.  
  310.     for (i=0; i<UI_NO_UPDATE_PARAMS; i++)
  311.     ui_updateParameters[i] = (float) 
  312.         ui_xFloatFromAsciiWidget(ui_updateParameterWidgets[i]);  
  313.  
  314.     /* erase selection markers */
  315.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); 
  316.  
  317.    /* Get new Activation Parameter for Kohonen */
  318.    if (kohonen_open) 
  319.      kohonen_SetExtraParameter(ui_xIntFromAsciiWidget(ui_LayerWidget)); 
  320.  
  321.     if (ui_workProcId)
  322.     XtRemoveWorkProc(ui_workProcId); /* kill old workProc */
  323.     ui_workType = UI_STEPS;
  324.     ui_workProcId = 
  325.     XtAppAddWorkProc(ui_appContext, (XtWorkProc) ui_rem_performStep, NULL);
  326.  
  327. }
  328.  
  329.  
  330. /*****************************************************************************
  331.   FUNCTION : ui_rem_moveInPatternsProc             
  332.  
  333.   PURPOSE  : callback. Called when clicked on a cursor button or the GOTO 
  334.              button.
  335.   RETURNS  : void
  336.   NOTES    :
  337.  
  338.   UPDATE   :
  339. *****************************************************************************/
  340. void ui_rem_moveInPatternsProc (Widget w, int moveType, caddr_t call_data)
  341. {
  342.     int   temp;
  343.  
  344.     Bool  doMove = FALSE;
  345.  
  346.     if (krui_getNoOfPatterns() <= 0) {
  347.     ui_confirmOk("No patterns in memory!");
  348.     return;
  349.     }
  350.  
  351.     /* there are patterns */
  352.     switch (moveType) {
  353.       case UI_JUMP: 
  354.     temp = ui_xIntFromAsciiWidget(ui_numberOfPatternWidget);
  355.     if ((temp > 0) AND (temp <= krui_getNoOfPatterns())) {
  356.         ui_noOfCurrentPattern = temp;
  357.         ui_rem_displayPatternNumber();
  358.         doMove = TRUE;
  359.     } else
  360.         ui_confirmOk("pattern goto: invalid number!");
  361.     break;
  362.       case UI_FIRST:
  363.     ui_noOfCurrentPattern = 1;
  364.     ui_rem_displayPatternNumber();
  365.     doMove = TRUE;
  366.     break;
  367.       case UI_LAST:
  368.     ui_noOfCurrentPattern = krui_getNoOfPatterns();
  369.     ui_rem_displayPatternNumber();
  370.     doMove = TRUE;
  371.     break;
  372.       case UI_NEXT:
  373.     if (++ui_noOfCurrentPattern > krui_getNoOfPatterns())
  374.         ui_noOfCurrentPattern = 1;
  375.     ui_rem_displayPatternNumber();
  376.     doMove = TRUE;
  377.     break;
  378.       case UI_PREVIOUS:
  379.     if (--ui_noOfCurrentPattern < 1)
  380.         ui_noOfCurrentPattern = krui_getNoOfPatterns();
  381.     ui_rem_displayPatternNumber();
  382.     doMove = TRUE;
  383.     break;
  384.     }
  385.     
  386.     if (doMove) {
  387.     /* new pattern: reset */
  388.  
  389.     krui_setPatternNo(ui_noOfCurrentPattern);
  390.     ui_rem_getSubPatPanel();
  391.     ui_rem_resetSubPat();
  392.     ui_checkError(krui_DefShowSubPat(subIPatSize,subOPatSize,
  393.                      subIPatPos,subOPatPos));
  394.     ui_rem_resetCounter();
  395.  
  396.     ui_checkError(krui_showPattern(ui_patternLoadMode));
  397.     ui_net_updateWhole(NULL, UI_GLOBAL, UI_DRAW_UNITS, UI_DRAW);
  398.     }
  399. }
  400.  
  401.  
  402. /*****************************************************************************
  403.   FUNCTION : ui_rem_moveInSubPattProc             
  404.  
  405.   PURPOSE  : callback. Called when clicked on a cursor button of the supattern 
  406.              panel.
  407.   RETURNS  : void
  408.   NOTES    :
  409.  
  410.   UPDATE   :
  411. *****************************************************************************/
  412.  
  413. void ui_rem_moveInSubPattProc (Widget w, int moveParam, caddr_t call_data)
  414. {
  415.     int dim, moveType;
  416.     int i;
  417.     pattern_set_info patt_info;
  418.     pattern_descriptor descrip;
  419.     char buf[3];
  420.     krui_err error;
  421.     int i_temp, o_temp, i_save, o_save;
  422.     int maxNpos;      /* value not used */
  423.  
  424.     /* Get information about current pattern set */
  425.  
  426.     if((error = krui_GetPatInfo(&patt_info, &descrip)) < 0){
  427.     ui_checkError(error);
  428.     return;
  429.     }
  430.  
  431.     /* extract parameters */
  432.  
  433.     dim = moveParam / 10;
  434.     moveType = moveParam % 10;
  435.  
  436.  
  437.     /* get subpattern information */
  438.  
  439.     for (i=0; i< subIPatDims; i++) {
  440.     subIPatSize[i] = (int)ui_xIntFromAsciiWidget(subIPatSizeW[i]);
  441.     subIPatStep[i] = (int)ui_xIntFromAsciiWidget(subIPatStepW[i]);
  442.     }
  443.     for (i=0; i< subOPatDims; i++) {
  444.     subOPatSize[i] = (int)ui_xIntFromAsciiWidget(subOPatSizeW[i]);
  445.     subOPatStep[i] = (int)ui_xIntFromAsciiWidget(subOPatStepW[i]);
  446.     }
  447.  
  448.  
  449.     /* compute the new subpattern positions */
  450.  
  451.     switch (moveType) {
  452.       case SP_FIRST:
  453.     i_temp = 1;
  454.     o_temp = 1;
  455.     break;
  456.       case SP_LAST:
  457.     i_temp = descrip.input_dim_sizes[dim] - subIPatSize[dim]+1;
  458.     o_temp = descrip.output_dim_sizes[dim] - subOPatSize[dim]+1;
  459.     break;
  460.       case SP_NEXT:
  461.     if(subIPatPos[dim]+subIPatStep[dim] <= 
  462.                           descrip.input_dim_sizes[dim]-subIPatSize[dim]+1)
  463.         i_temp = subIPatPos[dim] + subIPatStep[dim];
  464.     else
  465.         i_temp = subIPatPos[dim];
  466.     if(subOPatPos[dim]+subOPatStep[dim] <= 
  467.                           descrip.output_dim_sizes[dim]-subOPatSize[dim]+1)
  468.         o_temp = subOPatPos[dim] + subOPatStep[dim];
  469.     else
  470.         o_temp = subOPatPos[dim];
  471.     break;
  472.       case SP_PREVIOUS:
  473.     i_temp = subIPatPos[dim] - subIPatStep[dim];
  474.     if(i_temp < 1)i_temp = 1;
  475.     o_temp = subOPatPos[dim] - subOPatStep[dim];
  476.     if(o_temp < 1)o_temp = 1;
  477.     break;
  478.     }
  479.  
  480.     /* perform the move */
  481.     subIPatPos[dim] = i_temp;
  482.     subOPatPos[dim] = o_temp;
  483.  
  484.     /* validate the desired move */
  485.     ui_checkError(krui_DefTrainSubPat(subIPatSize,subOPatSize,        
  486.                       subIPatStep,subOPatStep,&maxNpos));
  487.     ui_checkError(krui_AlignSubPat(subIPatPos,subOPatPos,&subIPatNo));
  488.  
  489.     if((error = krui_DefShowSubPat(subIPatSize,subOPatSize,
  490.                    subIPatPos,subOPatPos)) < 0){
  491.     ui_checkError(error);
  492.     return;
  493.     }
  494.     if((error = krui_showPattern(ui_patternLoadMode)) < 0){
  495.     ui_checkError(error);
  496.     return;
  497.     }
  498.     ui_net_updateWhole(NULL, UI_GLOBAL, UI_DRAW_UNITS, UI_DRAW);
  499.  
  500.     /* reset labels if move was successful */
  501.     for (i=0; i< subIPatDims; i++) {
  502.     sprintf(buf," %d",subIPatPos[i]);
  503.     ui_xSetLabel(subIPatPosW[i],buf);
  504.     }
  505.     for (i=0; i< subOPatDims; i++){
  506.     sprintf(buf," %d",subOPatPos[i]);
  507.     ui_xSetLabel(subOPatPosW[i],buf);
  508.     }
  509. }
  510.  
  511.  
  512. /*****************************************************************************
  513.   FUNCTION : ui_rem_testProc
  514.  
  515.   PURPOSE  : load the next (or first) pattern and perform the number of steps
  516.              specified in the remote panel in "no of steps"
  517.   RETURNS  : void
  518.   NOTES    :
  519.  
  520.   UPDATE   :
  521. *****************************************************************************/
  522.  
  523. void ui_rem_testProc (Widget w, XtPointer button, caddr_t call_data)
  524.  
  525. {
  526.  
  527.     static int npos = 1;
  528.     int        maxNpos;
  529.  
  530.  
  531.     if (krui_getNoOfPatterns() == 0) {
  532.     char buf[80];
  533.     sprintf(buf,"No patterns present.");
  534.     ui_printMessage(buf);
  535.     return;
  536.     }
  537.  
  538.     /* there are patterns */
  539.  
  540.     if (ui_noOfCurrentPattern > krui_getNoOfPatterns() - 1)
  541.     ui_noOfCurrentPattern = 0; /* set before first pattern */
  542.  
  543.     rcc_currentPattern = ui_noOfCurrentPattern;
  544.  
  545.     /* new pattern: reset */
  546.     ui_rem_resetCounter();
  547.  
  548.     ui_rem_getSubPatPanel();
  549.     ui_checkError(krui_DefTrainSubPat(subIPatSize,subOPatSize,
  550.                       subIPatStep,subOPatStep,&maxNpos));
  551.     ui_checkError(krui_AlignSubPat(subIPatPos,subOPatPos,&npos));
  552.     if(++npos > maxNpos){
  553.     ui_checkError(krui_setPatternNo(++ui_noOfCurrentPattern));
  554.     ui_checkError(krui_DefTrainSubPat(subIPatSize,subOPatSize,
  555.                       subIPatStep,subOPatStep,&maxNpos));
  556.     npos = 1;
  557.     ui_rem_resetSubPat();
  558.     }
  559.     ui_checkError(krui_GetShapeOfSubPattern(subIPatSize,subOPatSize,
  560.                         subIPatPos,subOPatPos,npos));
  561.     ui_checkError(krui_DefShowSubPat(subIPatSize,subOPatSize,
  562.                      subIPatPos,subOPatPos));
  563.     ui_rem_setSubPatPanel();
  564.  
  565.     ui_checkError(krui_showPattern(ui_patternLoadMode));
  566.     ui_rem_displayPatternNumber();
  567.  
  568.     if (ui_xIntFromAsciiWidget(ui_numberOfStepsWidget) < 1)
  569.     ui_net_updateWhole(NULL, UI_GLOBAL, 
  570.                UI_DRAW_UNITS, UI_DRAW);
  571.     else
  572.     ui_rem_stepsProc(NULL, TRUE, NULL); /* multistep */
  573. }
  574.  
  575.  
  576. /*****************************************************************************
  577.   FUNCTION : ui_rem_deleteAllPatternsProc
  578.  
  579.   PURPOSE  : delete all patterns in main memory. The contents of the current
  580.              pattern file (if any) is left unchanged 
  581.   RETURNS  : void
  582.   NOTES    :
  583.  
  584.   UPDATE   : 24.8.1990
  585. ******************************************************************************/
  586.  
  587. void ui_rem_deleteAllPatternsProc (Widget w, XtPointer button, 
  588.                     caddr_t call_data)
  589.  
  590. {
  591.     if (ui_confirmYes("Delete all patterns. Are you sure?")) {
  592.     krui_deleteAllPatterns();
  593.     ui_noOfCurrentPattern = 0;
  594.     ui_rem_displayPatternNumber();
  595.     }
  596. }
  597.  
  598.  
  599. /*****************************************************************************
  600.   FUNCTION : ui_rem_modifyPatternProc
  601.  
  602.   PURPOSE  : calls the kernal in order to store the current visible pattern
  603.              replacing the current pattern. 
  604.   RETURNS  : void 
  605.   NOTES    :
  606.  
  607.   UPDATE   : 18.3.1991
  608. ******************************************************************************/
  609. void ui_rem_modifyPatternProc (Widget w, XtPointer button, caddr_t call_data)
  610. {
  611.     int temp = ui_xIntFromAsciiWidget(ui_numberOfPatternWidget);
  612.  
  613.     newPatternsLoaded = 1;
  614.  
  615.     if ((temp > 0) AND (temp <= krui_getNoOfPatterns())) {
  616.     ui_noOfCurrentPattern = temp;
  617.     krui_setPatternNo(ui_noOfCurrentPattern);
  618.     ui_checkError(krui_modifyPattern());
  619.     if (ui_noOfCurrentPattern > krui_getNoOfPatterns()) {
  620.         ui_noOfCurrentPattern = krui_getNoOfPatterns();
  621.         ui_rem_displayPatternNumber();
  622.     } 
  623.     } else
  624.     ui_confirmOk("modify pattern: invalid pattern number!");
  625. }
  626.  
  627.  
  628. /*****************************************************************************
  629.   FUNCTION : ui_rem_deletePatternProc
  630.  
  631.   PURPOSE  : calls the kernal in order to delete the current visible pattern.
  632.   RETURNS  : void
  633.   NOTES    :
  634.  
  635.   UPDATE   : 18.3.1991
  636. ******************************************************************************/
  637. void ui_rem_deletePatternProc (Widget w, XtPointer button, caddr_t call_data)
  638. {
  639.     int temp = ui_xIntFromAsciiWidget(ui_numberOfPatternWidget);
  640.  
  641.     newPatternsLoaded = 1;
  642.  
  643.     if ((temp > 0) AND (temp <= krui_getNoOfPatterns())) {
  644.     ui_noOfCurrentPattern = temp;
  645.     krui_setPatternNo(ui_noOfCurrentPattern);
  646.     ui_checkError(krui_deletePattern());
  647.     if (ui_noOfCurrentPattern > krui_getNoOfPatterns()) {
  648.         ui_noOfCurrentPattern = krui_getNoOfPatterns();
  649.         ui_rem_displayPatternNumber();
  650.     } 
  651.     } else
  652.     ui_confirmOk("delete pattern: invalid pattern number!");
  653. }
  654.  
  655.  
  656. /*****************************************************************************
  657.   FUNCTION : ui_rem_newPatternProc
  658.  
  659.   PURPOSE  : calls the kernel in order to store the current visible pattern
  660.              as a new one. This new pattern will be appended.
  661.   RETURNS  : void
  662.   NOTES    :
  663.  
  664.   UPDATE   : 24.8.1990
  665. ******************************************************************************/
  666. void ui_rem_newPatternProc (Widget w, XtPointer button, caddr_t call_data)
  667. {
  668.     pattern_set_info   patt_info;
  669.     pattern_descriptor descrip;
  670.     int error,setNo;
  671.  
  672.     if(NO_OF_PATTERN_SETS == 0){
  673.     if((error = krui_allocNewPatternSet(&setNo)) < 0){
  674.         ui_checkError(error);
  675.         return;
  676.     }
  677.     ui_noOfCurrentPattern = 1;
  678.     NO_OF_PATTERN_SETS = 1;
  679.     CURR_PATTERN_SET = setNo;
  680.  
  681.     /* set the widgets labels */
  682.     PATTERN_SET_FILE[CURR_PATTERN_SET] = (char *)malloc(8);
  683.     strcpy(PATTERN_SET_FILE[CURR_PATTERN_SET],"New Set");
  684.     ui_rem_updatePattList();
  685.  
  686.     }else if(krui_getNoOfPatterns() > 0){
  687.     if((error = krui_GetPatInfo(&patt_info, &descrip)) < 0){
  688.         ui_checkError(error);
  689.         return;
  690.     }
  691.     if(patt_info.in_number_of_dims>0 || patt_info.out_number_of_dims>0){
  692.         ui_confirmOk("NEW not allowed with variable sized patterns!");
  693.         return;
  694.     }
  695.     }
  696.  
  697.     newPatternsLoaded = 1;
  698.     ui_checkError(krui_newPattern());
  699.     ui_noOfCurrentPattern = krui_getNoOfPatterns();
  700.     ui_rem_displayPatternNumber();
  701. }
  702.  
  703.  
  704.  
  705. /*****************************************************************************
  706.   FUNCTION : ui_rem_printLearnInfo
  707.  
  708.   PURPOSE  : print information about last learning cycle
  709.   RETURNS  : void
  710.   NOTES    : Kohonen requires additional information to be displayed during
  711.              learning. Therefore a special section is included here.
  712.  
  713.   UPDATE   : 23.03.94 by Sven Doering
  714. ******************************************************************************/
  715. static void ui_rem_printLearnInfo (void)
  716. {
  717.     char    buf[MAX_NAME_LENGTH];
  718.     int     i,j;
  719.     static float temp1, temp2;
  720.     static int times = 1;
  721.     int pats;
  722.  
  723.     if(strcmp("Kohonen",krui_getLearnFunc()) == 0){
  724.     if(INIT_KOHONEN_PRINT == 1){
  725.         times = 1;
  726.         INIT_KOHONEN_PRINT = 0; /* The variable is set when pressing the
  727.                        ALL and SINGLE Buttons in the remote */
  728.         temp1 =(float)ui_xFloatFromAsciiWidget(ui_learnParameterWidgets[0]);
  729.         temp2 =(float)ui_xFloatFromAsciiWidget(ui_learnParameterWidgets[1]);
  730.     }else{
  731.         times = ui_numberOfLearnCycles DIV 10;
  732.     }
  733.     pats = krui_getNoOfPatterns();
  734.     for(j=1; j<= times; j++)
  735.         for(i=1; i<=pats; i++){
  736.         /* this is a copy of the adaption process in the kernel for
  737.            display reasons */
  738.         temp1 *= ui_learnParameters[2];
  739.         temp2 *= ui_learnParameters[3];
  740.         }
  741.     /* Adapt the displayed values of the first two learning parameters 
  742.        in the remote panel */
  743.     sprintf(buf,"%7.5f",temp1);
  744.     strncpy(buf,buf,7);
  745.     ui_xSetString(ui_learnParameterWidgets[0], buf);
  746.     sprintf(buf,"%7.5f",temp2);
  747.     strncpy(buf,buf,7);
  748.     ui_xSetString(ui_learnParameterWidgets[1], buf);
  749.     }
  750.  
  751.     sprintf(buf,"  %5d:", ui_numberOfWorkCycles + 1);
  752.     ui_tw_printMessage(buf);
  753.     sprintf(buf,"    %10.5f",ui_errorArray[0]);
  754.     ui_tw_printMessage(buf);
  755.     sprintf(buf,"     %10.5f",(ui_errorArray[0]/krui_getNoOfPatterns()));
  756.     ui_tw_printMessage(buf);
  757.     if (krui_getNoOfOutputUnits() > 0) {
  758.     sprintf(buf,"        %10.5f\n", 
  759.         (ui_errorArray[0]/krui_getNoOfOutputUnits()));
  760.     ui_tw_printMessage(buf);
  761.     } else
  762.     ui_tw_printMessage("\n");
  763. }
  764.  
  765.  
  766. /*****************************************************************************
  767.   FUNCTION : ui_rem_finishLearning
  768.  
  769.   PURPOSE  : finish performing learning cycles
  770.   RETURNS  : void
  771.   NOTES    :
  772.  
  773.   UPDATE   : 1.2.1990
  774. ******************************************************************************/
  775.  
  776. static void ui_rem_finishLearning (void)
  777.  
  778. {
  779.     /* bring the patterns back into their old order before shuffling was done */
  780.     if (ui_shuffleFlg) 
  781.     ui_checkError(krui_shufflePatterns(FALSE));
  782.     if (ui_shuffleSubPatFlg) 
  783.     ui_checkError(krui_shuffleSubPatterns(FALSE));
  784.     
  785.     if (ui_displ_isSomeWhereToShowWeights())
  786.     ui_net_completeRefresh(NULL, UI_GLOBAL);
  787.     else {
  788.           cc_updatePosOfSpecialUnits();
  789.           ui_net_completeRefresh(NULL, UI_GLOBAL);
  790.     ui_net_updateWhole(NULL, UI_GLOBAL, 
  791.                UI_DRAW_UNITS, UI_DRAW);
  792.     }
  793. }
  794.  
  795.  
  796. /*****************************************************************************
  797.   FUNCTION : ui_rem_performLearn
  798.  
  799.   PURPOSE  : perform learning cycles
  800.   RETURNS  :
  801.   NOTES    :
  802.  
  803.   UPDATE   : 1.2.1990
  804. ******************************************************************************/
  805.  
  806. static Boolean ui_rem_performLearn (int learnType)
  807.  
  808. {
  809.     krui_err err;
  810.  
  811.     dlvq_numberOfLearnCycles = ui_numberOfLearnCycles; 
  812.  
  813.     if (ui_numberOfWorkCycles-- < 1) {
  814.     ui_rem_finishLearning();
  815.     return(TRUE);
  816.     }
  817.  
  818.     switch (learnType) {
  819.       case UI_LEARN_ALL:
  820.     if (ui_shuffleFlg) 
  821.         ui_checkError(krui_shufflePatterns(TRUE));
  822.     if (ui_shuffleSubPatFlg) 
  823.         ui_checkError(krui_shuffleSubPatterns(TRUE));
  824.     ui_checkError(err = krui_learnAllPatterns(ui_learnParameters, 
  825.                    UI_NO_LEARN_PARAMS+UI_NO_OF_CASCADE_PARAMS,
  826.                         &ui_errorArray,
  827.                         &ui_noErrorArrayElements));
  828.         if (err != KRERR_NO_ERROR)
  829.             return (TRUE);
  830.     break;
  831.       case UI_LEARN_SINGLE:
  832.     if ((ui_noOfCurrentPattern <= krui_getNoOfPatterns()) AND
  833.         (ui_noOfCurrentPattern > 0)) {
  834.         ui_checkError(err = krui_learnSinglePattern(ui_noOfCurrentPattern,
  835.                           ui_learnParameters,
  836.                   UI_NO_LEARN_PARAMS+UI_NO_OF_CASCADE_PARAMS,
  837.                           &ui_errorArray,
  838.                           &ui_noErrorArrayElements));
  839.             if (err != KRERR_NO_ERROR)
  840.                 return (TRUE);
  841.     } else
  842.         ui_confirmOk("Can't learn current pattern.");
  843.     break;
  844.     }
  845.  
  846.     if ((ui_numberOfWorkCycles == ui_numberOfLearnCycles) or
  847.     (ui_numberOfWorkCycles == 0) or
  848.     (ui_numberOfLearnCycles <= 10) or
  849.     (((ui_numberOfWorkCycles+1) MOD (ui_numberOfLearnCycles DIV 10)) == 0)){
  850.     ui_rem_printLearnInfo();
  851.         ui_displWeightsFromUpdate();
  852.     }
  853.  
  854.     if(o_open){
  855.       o_draw(ui_errorArray[0]/krui_getNoOfOutputUnits());
  856.       if(ui_numberOfWorkCycles == 0){
  857.         o_PressPossible = 1;
  858.       }
  859.     }
  860.     return(FALSE);
  861. }
  862.  
  863.  
  864. /*****************************************************************************
  865.   FUNCTION : ui_rem_learnProc
  866.  
  867.   PURPOSE  : call the learn procedure of the kernel. The number of learn cycles
  868.              is determined by the user and also the learn parameter.
  869.   RETURNS  : implicite alteration of the network
  870.   NOTES    : 
  871.  
  872.   UPDATE   :
  873. *****************************************************************************/
  874.  
  875. void ui_rem_learnProc (Widget w, int learnType, caddr_t call_data)
  876.  
  877. {
  878.     char  buf[MAX_NAME_LENGTH];
  879.     int   i, maxNpos;
  880.     
  881.     o_PressPossible = 0;
  882.  
  883.       cc_readElements();
  884.       cc_allButtonIsPressed = 1;
  885.  
  886.     /* check now for errors and react ! */
  887.     if (krui_getNoOfPatterns == 0) {
  888.     ui_confirmOk("No patterns loaded/created!");
  889.     return;
  890.     }
  891.  
  892.     ui_rem_getSubPatPanel ();
  893.     ui_rem_resetSubPat();
  894.     ui_checkError(krui_DefTrainSubPat(subIPatSize,subOPatSize,
  895.                       subIPatStep,subOPatStep,&maxNpos));
  896.  
  897.     ui_numberOfWorkCycles = /* this value will be decreased */
  898.     ui_xIntFromAsciiWidget(ui_numberOfCyclesWidget);
  899.     ui_numberOfLearnCycles = /* this value stays constant */
  900.     ui_numberOfWorkCycles;
  901.     for (i=0; i<UI_NO_LEARN_PARAMS; i++)
  902.     ui_learnParameters[i] = (float) 
  903.         ui_xFloatFromAsciiWidget(ui_learnParameterWidgets[i]);
  904.     
  905.     if (learnType == UI_LEARN_ALL)
  906.     ui_tw_printMessage("\nLearning all patterns:\n");
  907.     else
  908.     ui_tw_printMessage("\nLearning current pattern:\n");
  909.  
  910.     sprintf(buf,
  911.         "  epochs   : %d\n  parameter: %8.5f\n  #o-units : %d\n  #patterns: %d\n", 
  912.         ui_numberOfWorkCycles, ui_learnParameters[0], 
  913.         krui_getNoOfOutputUnits(),krui_getNoOfPatterns());
  914.     ui_tw_printMessage(buf);
  915.     sprintf(buf,
  916.         "\n  epoch:         SSE            MSE            SSE/o-units\n\n");
  917.     ui_tw_printMessage(buf);
  918.     INIT_KOHONEN_PRINT = 1; /*Enables the print kommands for kohonen */
  919.     
  920.     NA_StopTest () ;
  921.     if (ui_workProcId)
  922.     XtRemoveWorkProc(ui_workProcId); /* kill old workProc */
  923.     ui_workType = UI_LEARN;
  924.     ui_workProcId = XtAppAddWorkProc(ui_appContext, 
  925.                      (XtWorkProc) ui_rem_performLearn, 
  926.                      (XtPointer) learnType); 
  927.  
  928. }
  929.  
  930.  
  931. /*****************************************************************************
  932.   FUNCTION : ui_rem_stopProc
  933.  
  934.   PURPOSE  : callback. Called after click on STOP button
  935.   RETURNS  : void
  936.   NOTES    :
  937.  
  938.   UPDATE   :
  939. *****************************************************************************/
  940.  
  941. void  ui_rem_stopProc (Widget widget, caddr_t client_data, caddr_t call_data)
  942.  
  943.     if (ui_workProcId) { 
  944.     switch (ui_workType) { 
  945.       case UI_STEPS: 
  946.         ui_rem_finishSteps(); break;
  947.       case UI_LEARN:
  948.         ui_rem_finishLearning();
  949.         ui_rem_printLearnInfo();
  950.         break;
  951.     }
  952.     NA_StopTest () ;
  953.     XtRemoveWorkProc(ui_workProcId); /* kill workProc */
  954.     ui_workProcId = 0;
  955.     ui_numberOfWorkCycles = 0;
  956.     }
  957.     o_PressPossible = 1;
  958. }
  959.  
  960.  
  961. /*****************************************************************************
  962.   FUNCTION : ui_rem_shuffleProc
  963.  
  964.   PURPOSE  : notify procedure of the toggle item, to remember the status of
  965.              it.
  966.   RETURNS  : changes the flag ui_shuffleFlg
  967.   NOTES    :
  968.  
  969.   UPDATE   :
  970. *****************************************************************************/
  971. void ui_rem_shuffleProc (Widget w, caddr_t client, caddr_t call)
  972. {
  973.     ui_shuffleFlg = ui_xGetToggleState(w);
  974. }
  975.  
  976.  
  977. /*****************************************************************************
  978.   FUNCTION : ui_rem_showModeProc
  979.  
  980.   PURPOSE  : notify procedure of the panel cycle.
  981.   RETURNS  : sets the variable ui_patternLoadMode
  982.   NOTES    :
  983.  
  984.   UPDATE   :
  985. *****************************************************************************/
  986. void ui_rem_showModeProc (Widget w, int value, caddr_t call_data)
  987. {    
  988.     ui_patternLoadMode = (int) value;
  989.     switch (value) {
  990.       case OUTPUT_NOTHING:
  991.     ui_xSetLabel(ui_showModeLabel, "none");
  992.     break;
  993.       case OUTPUT_OUT:
  994.     ui_xSetLabel(ui_showModeLabel, "output");
  995.     break;
  996.       case OUTPUT_ACT:
  997.     ui_xSetLabel(ui_showModeLabel, "activation");
  998.     break;
  999.     }
  1000. }
  1001.  
  1002.  
  1003. /*****************************************************************************
  1004.   FUNCTION : ui_rem_setRandomWeights
  1005.  
  1006.   PURPOSE  : set weights of all links randomly
  1007.   RETURNS  : void
  1008.   NOTES    :
  1009.  
  1010.   UPDATE   :
  1011. *****************************************************************************/
  1012. void ui_rem_setRandomWeights (Widget w, int randomType, caddr_t call_data)
  1013. {    
  1014.     FlintType  low, high, temp;
  1015.  
  1016.     low  = (FlintType) ui_xFloatFromAsciiWidget(ui_lowLimitWidget);
  1017.     high = (FlintType) ui_xFloatFromAsciiWidget(ui_highLimitWidget);
  1018.     if (low > high) {
  1019.     temp = low;
  1020.     low  = high;
  1021.     high = temp;
  1022.     }
  1023.  
  1024.     switch (randomType) {
  1025.       case UI_RANDOM:
  1026.     /* krui_randomizeWeights(low, high); */       
  1027.     break;
  1028.       case UI_JOG:
  1029.     krui_jogWeights(low, high);
  1030.     break;
  1031.     }
  1032.     if (ui_displ_isSomeWhereToShowWeights())
  1033.     ui_net_completeRefresh(NULL, UI_GLOBAL);
  1034. }
  1035.  
  1036.  
  1037. /*****************************************************************************
  1038.   FUNCTION : ui_rem_getKernelInfo
  1039.  
  1040.   PURPOSE  : get some info from the kernel. Output to text window
  1041.   RETURNS  : void
  1042.   NOTES    :
  1043.  
  1044.   UPDATE   : 1.2.1990
  1045. ******************************************************************************/
  1046. void ui_rem_getKernelInfo (Widget w, XtPointer button, caddr_t call_data)
  1047. {
  1048.     char   buf[127];
  1049.     int    no_of_sites, no_of_links, no_of_STable_entries, no_of_FTable_entries;
  1050.     int    unit_bytes, site_bytes, link_bytes, 
  1051.            NTable_bytes, STable_bytes, FTable_bytes;
  1052.  
  1053.     sprintf(buf,"\n%s :\n\n", krui_getVersion());
  1054.     ui_tw_printMessage(buf);
  1055.  
  1056.     krui_getNetInfo(&no_of_sites, &no_of_links,
  1057.             &no_of_STable_entries, &no_of_FTable_entries);
  1058.  
  1059.     sprintf(buf,"#input  units: %6d\n#output units: %6d\n#patterns    : %6d\n",
  1060.         krui_getNoOfInputUnits(), krui_getNoOfOutputUnits(), 
  1061.         krui_getNoOfPatterns());
  1062.     ui_tw_printMessage(buf);
  1063.     sprintf(buf,"#sites       : %6d\n#links       : %6d\n",
  1064.         no_of_sites, no_of_links);
  1065.     ui_tw_printMessage(buf);
  1066.     sprintf(buf,"#STable entr.: %6d\n#FTable-Entr.: %6d\n\n",
  1067.         no_of_STable_entries, no_of_FTable_entries);
  1068.     ui_tw_printMessage(buf);
  1069.  
  1070.     ui_tw_printMessage("sizes in bytes:\n");
  1071.     krui_getMemoryManagerInfo(&unit_bytes, &site_bytes, &link_bytes,
  1072.                   &NTable_bytes, &STable_bytes, &FTable_bytes);
  1073.     sprintf(buf,"units        : %7d\nsites        : %7d\nlinks        : %7d\n",
  1074.         unit_bytes, site_bytes, link_bytes);
  1075.     ui_tw_printMessage(buf);
  1076.     sprintf(buf,"NTable       : %7d\nSTable       : %7d\nFTable       : %7d\n\n"
  1077.         ,NTable_bytes, STable_bytes, FTable_bytes);
  1078.     ui_tw_printMessage(buf);
  1079.     sprintf(buf,"learning function  : %s\n", krui_getLearnFunc());
  1080.     ui_tw_printMessage(buf);
  1081.     sprintf(buf,"update function    : %s\n", krui_getUpdateFunc());
  1082.     ui_tw_printMessage(buf);
  1083.     sprintf(buf,"initialize function: %s\n", krui_getInitialisationFunc());
  1084.     ui_tw_printMessage(buf);
  1085.  
  1086.     ui_tw_printMessage("\n\n");
  1087. }
  1088.  
  1089.  
  1090. /*****************************************************************************
  1091.   FUNCTION : ui_rem_shuffleSubPatProc
  1092.  
  1093.   PURPOSE  : notify procedure of the toggle item, to remember the status of
  1094.              it.
  1095.   RETURNS  : changes the flag ui_shuffleSubPatFlg
  1096.   NOTES    :
  1097.  
  1098.   UPDATE   :
  1099. *****************************************************************************/
  1100. void ui_rem_shuffleSubPatProc (Widget w, caddr_t client, caddr_t call)
  1101. {
  1102.     ui_shuffleSubPatFlg = ui_xGetToggleState(w);
  1103. }
  1104.  
  1105.  
  1106. /*****************************************************************************
  1107.   FUNCTION : ui_rem_defSubPat
  1108.  
  1109.   PURPOSE  : creates the panel to handle sub patterns 
  1110.   RETURNS  : void
  1111.   NOTES    :
  1112.  
  1113.   UPDATE   : 16.09.1993
  1114. ******************************************************************************/
  1115. void ui_rem_defSubPat (Widget button, int refreshType, caddr_t call_data)
  1116. {
  1117.     Widget             sbutton,lab1,ui_pop_exit,ui_pop,above,
  1118.                        isize,istep,itot,otot,osize,ostep;
  1119.     static Widget      form,title1,title2,left,subPatDoneW,
  1120.                        input,output,ipos,opos;
  1121.     Arg                args[5];
  1122.     Position           x, y;
  1123.     Dimension          width, height;
  1124.     Cardinal           n;
  1125.     char               buf[120];
  1126.     int                i;
  1127.     krui_err           error;
  1128.     pattern_set_info   patt_info;
  1129.     pattern_descriptor descrip;
  1130.     Window             rdummy;
  1131.     int                x1, y1, border;
  1132.     unsigned int       wdummy, hdummy, bdummy, ddummy;
  1133.  
  1134.  
  1135.     /* Get information about current pattern set */
  1136.  
  1137.     if(NO_OF_PATTERN_SETS == 0){
  1138.     if(refreshType == 0){
  1139.         ui_confirmOk("No Patterns present !");
  1140.         return;
  1141.     }else{
  1142.         /* call came from ui_rem_delPatSet which deleted last pattern */
  1143.         /* set. Therefore destroy panel                               */
  1144.         XtCallCallbacks(subPatDoneW,XtNcallback,
  1145.                 (caddr_t) UI_POPUP_SUBPATTERN);
  1146.         return;
  1147.     }
  1148.     }
  1149.  
  1150.  
  1151.     if((refreshType == 1) && (SubPatPanel < 1))
  1152.     /* can't refresh, if panel was never created yet */
  1153.     return;
  1154.  
  1155.     if((error = krui_GetPatInfo(&patt_info, &descrip)) < 0){
  1156.     ui_checkError(error);
  1157.     return;
  1158.     }
  1159.  
  1160.     if(patt_info.in_number_of_dims == 0){
  1161.     if(SubPatPanel < 1){
  1162.         ui_confirmOk("Pattern has no variable dimension !");
  1163.         return;
  1164.     }else{
  1165.         /* New pattern set does not allow this panel */
  1166.         XtCallCallbacks(subPatDoneW,XtNcallback,
  1167.                 (caddr_t) UI_POPUP_SUBPATTERN);
  1168.         return;
  1169.     }
  1170.  
  1171.     }
  1172.  
  1173.     if(refreshType == 0){ /*panel has to be created */
  1174.  
  1175.     if(SubPatPanel == 1)
  1176.         /* panel was supposed to be created but exists already */
  1177.         return;
  1178.  
  1179.     /* Upper left corner will be in the center of the calling button */
  1180.  
  1181.     ui_xGetDimensions(button, &width, &height);
  1182.     XtTranslateCoords(button, (Position) (width / 2), 
  1183.               (Position) (height / 2),&x, &y);
  1184.     
  1185.     n = 0;
  1186.     XtSetArg(args[n], XtNx, x); n++;
  1187.     XtSetArg(args[n], XtNy, y); n++;
  1188.  
  1189.     /* Now create Popup */
  1190.     
  1191.     ui_popPattern =
  1192.         XtCreatePopupShell("Sub Pattern Handling", 
  1193.                 topLevelShellWidgetClass,ui_toplevel,args,n);
  1194.     }else{
  1195.  
  1196.     /* Recreate the panel */
  1197.  
  1198.     n = 0;
  1199.     XtSetArg(args[n], XtNx, &x); n++;
  1200.     XtSetArg(args[n], XtNy, &y); n++;
  1201.     XtSetArg(args[n], XtNborderWidth, &border); n++;
  1202.     XtGetValues(ui_popPattern, args, n);
  1203.     XGetGeometry(ui_display, (*ui_popPattern).core.window, &rdummy, 
  1204.              &x1, &y1, &wdummy, &hdummy, &bdummy, &ddummy);
  1205.     XtDestroyWidget(ui_popPattern);
  1206.  
  1207.     n = 0;
  1208.     XtSetArg(args[n], XtNx, x-x1-bdummy-1); n++;
  1209.     XtSetArg(args[n], XtNy, y-y1-bdummy-1); n++;
  1210.         ui_popPattern =
  1211.         XtCreatePopupShell("Sub Pattern Handling", 
  1212.                 transientShellWidgetClass,ui_toplevel,args,n);
  1213.     }
  1214.     ui_pop = 
  1215.     XtCreateManagedWidget("frame",formWidgetClass,ui_popPattern,
  1216.                   NULL,0);
  1217.     
  1218.     XtSetArg(args[n], XtNborderWidth, 1); 
  1219.     form = XtCreateManagedWidget("form", formWidgetClass, ui_pop, args, 1);
  1220.     
  1221.     sprintf(buf,"                               Input");
  1222.     title1 = ui_xCreateLabelItem(buf,form,41*8,NULL,NULL);
  1223.     sprintf(buf,"       Output");
  1224.     title2 = ui_xCreateLabelItem(buf,form,14*8,title1,NULL);
  1225.     
  1226.     n = 0;
  1227.     XtSetArg(args[n], XtNborderWidth,  0); n++;
  1228.     XtSetArg(args[n], XtNfromHoriz, NULL); n++;
  1229.     XtSetArg(args[n], XtNfromVert, title1); n++;
  1230.     left = XtCreateManagedWidget("left", formWidgetClass, form, args, n);
  1231.     sprintf(buf,"     ");
  1232.     title1 = ui_xCreateLabelItem(buf,left,9*8,NULL,NULL);
  1233.  
  1234.     sbutton = ui_xCreateToggleItem("shuffle", left, NULL, title1, NULL);
  1235.     XtAddCallback(sbutton, XtNcallback, 
  1236.           (XtCallbackProc) ui_rem_shuffleSubPatProc, NULL);
  1237.  
  1238.     subIPatDims = patt_info.in_number_of_dims;
  1239.     subOPatDims = patt_info.out_number_of_dims;
  1240.  
  1241.     above = sbutton;
  1242.  
  1243.     for (i=0; i< subIPatDims; i++) {
  1244.         sprintf(buf,"dim %d :",i+1);
  1245.     lab1 = ui_xCreateLabelItem(buf, left, 7*8, NULL, above);
  1246.  
  1247.     sbutton = ui_xCreateButtonItem("first",left,lab1,above);
  1248.     XtAddCallback(sbutton, XtNcallback, 
  1249.               (XtCallbackProc)ui_rem_moveInSubPattProc,
  1250.               (caddr_t)(SP_FIRST + i*10));
  1251.     
  1252.     sbutton = ui_xCreateButtonItem("prev",left, sbutton, above);
  1253.     XtAddCallback(sbutton, XtNcallback, 
  1254.               (XtCallbackProc)ui_rem_moveInSubPattProc,
  1255.               (caddr_t)(SP_PREVIOUS + i*10));
  1256.  
  1257.     sbutton = ui_xCreateButtonItem("next",left, sbutton, above);
  1258.     XtAddCallback(sbutton, XtNcallback, 
  1259.               (XtCallbackProc) ui_rem_moveInSubPattProc,
  1260.               (caddr_t) (SP_NEXT + i*10));
  1261.  
  1262.     sbutton = ui_xCreateButtonItem("last",left, sbutton, above);
  1263.     XtAddCallback(sbutton, XtNcallback,
  1264.               (XtCallbackProc) ui_rem_moveInSubPattProc,
  1265.               (caddr_t) (SP_LAST + i*10));
  1266.     
  1267.     above = lab1;
  1268.     }
  1269.  
  1270.     n = 0;
  1271.     XtSetArg(args[n], XtNborderWidth,  1); n++;
  1272.     XtSetArg(args[n], XtNfromHoriz, left); n++;
  1273.     XtSetArg(args[n], XtNfromVert, title1); n++;
  1274.     input  = XtCreateManagedWidget("input", formWidgetClass, form, args, n);
  1275.     ipos  = ui_xCreateLabelItem("Pos ",input,4*8,NULL,NULL);
  1276.     itot  = ui_xCreateLabelItem("Tot ",input,4*8,ipos,NULL);
  1277.     isize = ui_xCreateLabelItem("Size",input,4*8,itot,NULL);
  1278.     istep = ui_xCreateLabelItem("Step",input,4*8,isize,NULL);
  1279.  
  1280.     above = ipos;
  1281.  
  1282.     for (i=0; i< subIPatDims; i++) {
  1283.         sprintf(buf," %d",subIPatPos[i]);
  1284.     subIPatPosW[i] = ui_xCreateLabelItem(buf,input,4*8,NULL,above);
  1285.  
  1286.         sprintf(buf," %d",descrip.input_dim_sizes[i]);
  1287.     in_dim_widgets[i] = ui_xCreateLabelItem(buf,input,5*8,
  1288.                            subIPatPosW[i],above);
  1289.         sprintf(buf,"%d",subIPatSize[i]);
  1290.         subIPatSizeW[i] = ui_xCreateDialogItem("param",input,buf,4*8,
  1291.                            in_dim_widgets[i],above);
  1292.  
  1293.         sprintf(buf,"%d",subIPatStep[i]);
  1294.     subIPatStepW[i] = ui_xCreateDialogItem("param",input,buf,4*8, 
  1295.                            subIPatSizeW[i],above);
  1296.  
  1297.     above = subIPatPosW[i];
  1298.  
  1299.     }
  1300.  
  1301.     n = 0;
  1302.     XtSetArg(args[n], XtNborderWidth,  1); n++;
  1303.     XtSetArg(args[n], XtNfromHoriz, input); n++;
  1304.     XtSetArg(args[n], XtNfromVert, title2); n++;
  1305.     output = XtCreateManagedWidget("output",formWidgetClass,form,args,n);
  1306.     opos  = ui_xCreateLabelItem("Pos ",output,4*8,NULL,NULL);
  1307.     otot  = ui_xCreateLabelItem("Tot ",output,4*8,opos,NULL);
  1308.     osize = ui_xCreateLabelItem("Size",output,4*8,otot,NULL);
  1309.     ostep = ui_xCreateLabelItem("Step",output,4*8,osize,NULL);
  1310.     
  1311.     above = opos;
  1312.  
  1313.     for (i=0; i<subOPatDims; i++) {
  1314.         sprintf(buf," %d",subOPatPos[i]);
  1315.     subOPatPosW[i]  = ui_xCreateLabelItem(buf,output,4*8,NULL,above);
  1316.  
  1317.         sprintf(buf," %d",descrip.output_dim_sizes[i]);
  1318.         out_dim_widgets[i] = ui_xCreateLabelItem(buf,output,5*8,
  1319.                             subOPatPosW[i],above);
  1320.         sprintf(buf,"%d",subOPatSize[i]);
  1321.         subOPatSizeW[i] = ui_xCreateDialogItem("param",output,buf,4*8,
  1322.                            out_dim_widgets[i],above);
  1323.  
  1324.         sprintf(buf,"%d",subOPatStep[i]);
  1325.         subOPatStepW[i] = ui_xCreateDialogItem("param",output,buf,4*8, 
  1326.                            subOPatSizeW[i],above);
  1327.  
  1328.     above = subOPatStepW[i];
  1329.  
  1330.     }
  1331.  
  1332.     
  1333.     subPatDoneW = ui_xCreateButtonItem("done", ui_pop, NULL, form);
  1334.     XtAddCallback(subPatDoneW, XtNcallback, (XtCallbackProc) ui_popupDone, 
  1335.           (caddr_t) UI_POPUP_SUBPATTERN);
  1336.                   /*!*/  /* constant name is meaningless ! */
  1337.  
  1338.     ui_checkWindowPosition(ui_popPattern);
  1339.     XtPopup(ui_popPattern, XtGrabNone);
  1340.     ui_xDontResizeWidget(ui_popPattern); 
  1341.     SubPatPanel = 1;
  1342. }
  1343.  
  1344.  
  1345.  
  1346.  
  1347. /*****************************************************************************
  1348.   FUNCTION : ui_rem_usePattSet
  1349.  
  1350.   PURPOSE  : Switches between different pattern sets
  1351.   RETURNS  : void
  1352.   NOTES    :
  1353.  
  1354.   UPDATE   : 13.09.1991
  1355. ******************************************************************************/
  1356. void ui_rem_usePattSet (Widget button, int setNo, caddr_t call_data)
  1357. {
  1358.     int error;
  1359.  
  1360.  
  1361.     if(CURR_PATTERN_SET == setNo)
  1362.     return;
  1363.  
  1364.     if((error = krui_setCurrPatSet(setNo)) < 0){
  1365.     ui_checkError(error);
  1366.     return;
  1367.     }
  1368.  
  1369.     CURR_PATTERN_SET = setNo;
  1370.     ui_noOfCurrentPattern = 1;
  1371.     ui_xSetLabel(ui_showPattFile, PATTERN_SET_FILE[CURR_PATTERN_SET]);
  1372.  
  1373.  
  1374.     /* refresh the subpattern panel */
  1375.     ui_rem_defSubPat(button,1,(caddr_t)1);
  1376.  
  1377.     /* refresh the pattern panel */
  1378.     ui_rem_displayPatternNumber();
  1379. }
  1380.  
  1381.  
  1382.  
  1383.  
  1384. /*****************************************************************************
  1385.   FUNCTION : ui_rem_delPattSet
  1386.  
  1387.   PURPOSE  : deletes a pattern set
  1388.   RETURNS  : void
  1389.   NOTES    : DELPattFileWidget[0] and USEPattFileWidget[0] ALWAYS have 
  1390.              callbacks defined, even when the label shows "No Files" !
  1391.          This function has to take care that nothing happens in case no 
  1392.          files are present
  1393.  
  1394.   UPDATE   : 11.11.1991
  1395. ******************************************************************************/
  1396. void ui_rem_delPattSet (Widget button, int setNo, caddr_t call_data)
  1397. {
  1398.     Arg arg[10];
  1399.     char buf[80];
  1400.     int  i;
  1401.     Widget tempWidget;
  1402.  
  1403.  
  1404.     if(NO_OF_PATTERN_SETS == 0)
  1405.     return;
  1406.  
  1407.     /* check whether the pattern to be deleted is the current one */
  1408.  
  1409.     NO_OF_PATTERN_SETS--;
  1410.     if(CURR_PATTERN_SET == setNo){
  1411.     if(CURR_PATTERN_SET == NO_OF_PATTERN_SETS)
  1412.         CURR_PATTERN_SET = 0;          /* make the first one current */
  1413.     else
  1414.         CURR_PATTERN_SET = NO_OF_PATTERN_SETS;
  1415.                                        /* make the last one current */
  1416.     if(NO_OF_PATTERN_SETS == 0){       /* it was the only one        */
  1417.         sprintf(buf,"Patternfile ?");
  1418.         ui_xSetLabel(ui_showPattFile, buf);
  1419.         PATTERN_SET_FILE[0] = NULL;
  1420.         XtRemoveAllCallbacks(USEPattFileWidget[0],XtNcallback);
  1421.         XtRemoveAllCallbacks(DELPattFileWidget[0],XtNcallback);
  1422.         tempWidget = XtParent(USEPattFileWidget[0]);
  1423.         XtDestroyWidget(USEPattFileWidget[0]);
  1424.         USEPattFileWidget[0] = 
  1425.         XtCreateManagedWidget("No Files", smeBSBObjectClass, 
  1426.                       tempWidget, NULL, 0);
  1427.         XtAddCallback(USEPattFileWidget[0], XtNcallback, 
  1428.               (XtCallbackProc)ui_rem_usePattSet,(caddr_t)0);
  1429.         tempWidget = XtParent(DELPattFileWidget[0]);
  1430.         XtDestroyWidget(DELPattFileWidget[0]);
  1431.         DELPattFileWidget[0] = 
  1432.         XtCreateManagedWidget("No Files", smeBSBObjectClass, 
  1433.                       tempWidget, NULL, 0);
  1434.         XtAddCallback(DELPattFileWidget[0], XtNcallback, 
  1435.               (XtCallbackProc)ui_rem_delPattSet,(caddr_t)0);
  1436.         if(SubPatPanel == 1)
  1437.         ui_popupDone(tempWidget, UI_POPUP_SUBPATTERN , (caddr_t) 0);
  1438.  
  1439.     }else{
  1440.         sprintf(buf,"%s",PATTERN_SET_FILE[CURR_PATTERN_SET]);
  1441.     }
  1442.     ui_xSetLabel(ui_showPattFile, buf);
  1443.     }
  1444.  
  1445.     /* delete the pattern set now */
  1446.  
  1447.     ui_checkError(krui_deletePatSet(setNo));
  1448.  
  1449.     if(NO_OF_PATTERN_SETS == 0)    return;
  1450.  
  1451.     /* kernel needs resetting of current pattern */
  1452.     if(CURR_PATTERN_SET < setNo)
  1453.     krui_setCurrPatSet(CURR_PATTERN_SET);
  1454.     else
  1455.     krui_setCurrPatSet(--CURR_PATTERN_SET);
  1456.  
  1457.  
  1458.     /* refresh the subpattern panel */
  1459.     
  1460.     ui_rem_defSubPat(button,1,(caddr_t)1);
  1461.  
  1462.  
  1463.     /* Compact the array of pattern file names and relabel the menus*/
  1464.  
  1465.     for(i=setNo; i<NO_OF_PATTERN_SETS; i++){
  1466.     strcpy(PATTERN_SET_FILE[i],PATTERN_SET_FILE[i+1]);
  1467.     XtSetArg(arg[0],XtNlabel,PATTERN_SET_FILE[i]);
  1468.     XtSetValues(USEPattFileWidget[i],arg,1);
  1469.     XtSetValues(DELPattFileWidget[i],arg,1);
  1470.     }
  1471.  
  1472.     /* destroy the widgets corresponding to the deleted pattern */
  1473.  
  1474.     if(NO_OF_PATTERN_SETS > 0){
  1475.     XtRemoveAllCallbacks(USEPattFileWidget[NO_OF_PATTERN_SETS],XtNcallback);
  1476.     XtRemoveAllCallbacks(DELPattFileWidget[NO_OF_PATTERN_SETS],XtNcallback);
  1477.     XtDestroyWidget(USEPattFileWidget[NO_OF_PATTERN_SETS]);
  1478.     XtDestroyWidget(DELPattFileWidget[NO_OF_PATTERN_SETS]);
  1479.     USEPattFileWidget[NO_OF_PATTERN_SETS] = NULL;
  1480.     DELPattFileWidget[NO_OF_PATTERN_SETS] = NULL;
  1481.     }
  1482.  
  1483. }
  1484.  
  1485.  
  1486.  
  1487. /*****************************************************************************
  1488.   FUNCTION : ui_rem_updatePattList
  1489.  
  1490.   PURPOSE  : Updates the lists of available pattern sets.
  1491.              Both the list under the DEL and the USE button are updated.
  1492.   RETURNS  : void
  1493.   NOTES    : Remote panel has to be created before the call to this function
  1494.  
  1495.   UPDATE   : 13.09.1991
  1496. ******************************************************************************/
  1497. void ui_rem_updatePattList (void)
  1498. {
  1499.  
  1500.     Widget entry;
  1501.     int i;
  1502.     int n = 1;
  1503.     Arg arg[10];
  1504.     char temp[80];
  1505.  
  1506.  
  1507.     /* check whether any pattern files are loaded */
  1508.  
  1509.     if(PATTERN_SET_FILE[CURR_PATTERN_SET] != NULL){
  1510.  
  1511.     for(i=0; i<NO_OF_PATTERN_SETS;i++){       /* for all available files */
  1512.         XtSetArg(arg[0],XtNlabel,PATTERN_SET_FILE[i]);
  1513.  
  1514.         /* if the widgets do not exist already, create them now */
  1515.         /* else update only their labels                        */
  1516.  
  1517.         if(USEPattFileWidget[i] == NULL){
  1518.         USEPattFileWidget[i] = 
  1519.             XtCreateManagedWidget(PATTERN_SET_FILE[i],
  1520.                       smeBSBObjectClass,
  1521.                       REM_UFileMenu,NULL,0);
  1522.         XtAddCallback(USEPattFileWidget[i], XtNcallback, 
  1523.                   (XtCallbackProc)ui_rem_usePattSet,(caddr_t)i);
  1524.         }else{
  1525.         XtSetValues(USEPattFileWidget[i],arg,n);
  1526.         }
  1527.  
  1528.         if(DELPattFileWidget[i] == NULL){
  1529.         DELPattFileWidget[i] = 
  1530.             XtCreateManagedWidget(PATTERN_SET_FILE[i],
  1531.                       smeBSBObjectClass,
  1532.                        REM_DFileMenu,NULL,0);
  1533.         XtAddCallback(DELPattFileWidget[i], XtNcallback, 
  1534.                   (XtCallbackProc)ui_rem_delPattSet,(caddr_t)i);
  1535.         }else{
  1536.         XtSetValues(DELPattFileWidget[i],arg,n);
  1537.         }
  1538.     }
  1539.  
  1540.     }else{
  1541.  
  1542.     /* if no files are loaded make a comment */
  1543.     USEPattFileWidget[0] = 
  1544.         XtCreateManagedWidget("No Files",smeBSBObjectClass, 
  1545.                   REM_DFileMenu, NULL, 0);
  1546.     }
  1547. }
  1548.  
  1549.  
  1550.  
  1551. /*****************************************************************************
  1552.   FUNCTION : ui_rem_resetSubPat
  1553.  
  1554.   PURPOSE  : resets the values of the subpattern panel
  1555.   RETURNS  : void
  1556.   NOTES    :
  1557.  
  1558.   UPDATE   : 16.09.1993
  1559. ******************************************************************************/
  1560. static void ui_rem_resetSubPat (void)
  1561. {
  1562.  
  1563.     int                i;
  1564.  
  1565.     for(i=0; i< subIPatDims; i++) subIPatPos[i] = 1;
  1566.     for(i=0; i< subOPatDims; i++) subOPatPos[i] = 1;
  1567.     
  1568.     ui_rem_setSubPatPanel();
  1569.  
  1570. }
  1571.  
  1572.  
  1573. /*****************************************************************************
  1574.   FUNCTION : ui_rem_setSubPatPanel
  1575.  
  1576.   PURPOSE  : sets all values for the subpattern panel
  1577.   RETURNS  : void
  1578.   NOTES    :
  1579.  
  1580.   UPDATE   : 16.09.1993
  1581. ******************************************************************************/
  1582. static void ui_rem_setSubPatPanel (void)
  1583. {
  1584.  
  1585.     char               buf[20];
  1586.     int                i;
  1587.     pattern_set_info   patt_info;
  1588.     pattern_descriptor descrip;
  1589.     krui_err           error;
  1590.  
  1591.     if(SubPatPanel == 1){
  1592.     if((error = krui_GetPatInfo(&patt_info, &descrip))< 0){
  1593.         ui_checkError(error);
  1594.         return;
  1595.     }
  1596.     for (i=0; i< subIPatDims; i++) {
  1597.         sprintf(buf," %d",subIPatPos[i]);
  1598.         ui_xSetLabel(subIPatPosW[i],buf);
  1599.         sprintf(buf," %d",subIPatStep[i]);
  1600.         ui_xSetLabel(subIPatStepW[i],buf);
  1601.         sprintf(buf," %d",descrip.input_dim_sizes[i]);
  1602.         ui_xSetLabel(in_dim_widgets[i],buf);
  1603.     } 
  1604.     for (i=0; i< subOPatDims; i++) {
  1605.         sprintf(buf," %d",subOPatPos[i]);
  1606.         ui_xSetLabel(subOPatPosW[i],buf);
  1607.         sprintf(buf," %d",subOPatStep[i]);
  1608.         ui_xSetLabel(subOPatStepW[i],buf);
  1609.         sprintf(buf," %d",descrip.output_dim_sizes[i]);
  1610.         ui_xSetLabel(out_dim_widgets[i],buf);
  1611.     } 
  1612.     }
  1613.  
  1614.  
  1615. }
  1616.  
  1617. /*****************************************************************************
  1618.   FUNCTION : ui_rem_getSubPatPanel
  1619.  
  1620.   PURPOSE  : read all values from the subpattern panel
  1621.   RETURNS  : void
  1622.   NOTES    :
  1623.  
  1624.   UPDATE   : 16.09.1993
  1625. ******************************************************************************/
  1626. void ui_rem_getSubPatPanel (void)
  1627. {
  1628.     int i;
  1629.  
  1630.     if(SubPatPanel == 1){
  1631.     for(i=0; i<subIPatDims; i++) {
  1632.         subIPatStep[i] = ui_xIntFromAsciiWidget(subIPatStepW[i]);
  1633.         subIPatSize[i] = ui_xIntFromAsciiWidget(subIPatSizeW[i]);
  1634.     }
  1635.     for(i=0; i<subOPatDims; i++) {
  1636.         subOPatStep[i] = ui_xIntFromAsciiWidget(subOPatStepW[i]);
  1637.         subOPatSize[i] = ui_xIntFromAsciiWidget(subOPatSizeW[i]);
  1638.     }
  1639.     }
  1640. }
  1641. /* end of file */
  1642. /* lines: 1656 */
  1643.  
  1644.  
  1645.